﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Entity;
using IBusinessLogicLayer;

namespace MVC.Controllers
{
    public class StoreController : Controller
    {
        private IBaseBll<Genre> bll;
        private IBaseBll<Album> albumBll; 

        public StoreController(IBaseBll<Genre> bll, IBaseBll<Album> albumBll)
        {
            this.bll = bll;
            this.albumBll = albumBll;
        } 
        // GET: Store
        public ActionResult Index()
        {
            var genres = bll.Find(c => true);
            return View(genres);
        }

        public ActionResult Browse(string genre)
        {
            var genreModel = bll.FindSingle(c => c.Name == genre);
            if (genreModel == null) return HttpNotFound();
            genreModel.Albums = albumBll.Find(c => c.GenreId == genreModel.Id);
            return View(genreModel);
        }

        public ActionResult Details(int id)
        {
            return View(albumBll.FindSingle(a => a.Id == id));
        }

        [ChildActionOnly]
        public ActionResult GenreMenu()
        {
            var genres = bll.GetQueryable().ToList();

            return PartialView(genres);
        }
    }
}